﻿/*
 * Copyright(C) 2012,ajayumi 保留所有权利。( All rights reserved. )
 * 
 * 文件名称：Utility.cs
 * 摘    要：
 * 当前版本：1.0
 * 作    者：黄乙冬 (ajayumi)
 * 创建日期：2012年5月24日
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ajayumi.Platform.Web;

namespace ajayumi.Test.WebUI.Utils
{
    public class Utility
    {
        /// <summary>
        /// 获取登录超时的脚本字符串
        /// </summary>
        /// <returns></returns>
        public static string GetTimeoutReference()
        {
            string scriptStr = JQueryScript.GetMessageBoxReference(
                       string.Empty,
                       "登录超时",
                       true,
                       true,
                       400,
                       60,
                       JQueryScript.Effects.Explode,
                       JQueryScript.Effects.Explode,
                       1000 * 3,
                       string.Format("top.location='{0}'", VirtualPathUtility.ToAbsolute("~/Login.aspx")));
            return scriptStr;
        }

        /// <summary>
        /// 获取带跳转功能的对话框脚本字符串
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="content">对话框中的信息</param>
        /// <param name="url">跳转的地址，例如：~/default.aspx</param>
        /// <returns></returns>
        public static string GetMessageBoxReference(string title, string content, string url)
        {
            string scriptStr = JQueryScript.GetMessageBoxReference(title,
                content, false, false, 300, 150,
                JQueryScript.Effects.None,
                JQueryScript.Effects.None,
                3000,
                string.Format("top.location='{0}'", VirtualPathUtility.ToAbsolute(url)));
            return scriptStr;
        }

        /// <summary>
        /// 获取保存在Cookie中的区域语言字符串
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public static string GetLanguageFromCookie()
        {
            string lng = HttpHelper.ReadCookie(Constants.Language_Key);
            if (string.IsNullOrEmpty(lng))
            { lng = "en"; }
            return lng;
        }

        /// <summary>
        /// 将区域语言字符串保存到Cookie中
        /// </summary>
        public static void SetLanguageToCookie(string value)
        {
            HttpHelper.WriteCookie(Constants.Language_Key, value, DateTime.Now.AddYears(1));
        }

        /// <summary>
        /// 将成功的信息显示在Literal中
        /// </summary>
        /// <param name="literal"></param>
        /// <param name="msg">信息，不带样式</param>
        internal static void ShowSuccessMsg(System.Web.UI.WebControls.Literal literal, string msg)
        {
            literal.Text = string.Format("<div class=\"ui-state-highlight ui-cornet-all\" style=\"padding: 4px; margin: 4px auto; text-align:center\">{0}</div>", msg);
        }

        /// <summary>
        /// 将错误信息显示在Literal中
        /// </summary>
        /// <param name="literal"></param>
        /// <param name="msg">信息，不带样式</param>
        internal static void ShowErrorMsg(System.Web.UI.WebControls.Literal literal, string msg)
        {
            literal.Text = string.Format("<div class=\"ui-state-error ui-cornet-all\" style=\"padding: 4px; margin: 4px auto; text-align:center\">{0}</div>", msg);
        }
    }
}